package com.page.controller;

import com.jfinal.core.Controller;
import com.page.model.User;
import com.vo.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UserController extends Controller {

    private static Logger logger = LoggerFactory.getLogger(UserController.class);
    private AjaxResult result = new AjaxResult();

    public void index() {
        render("test.html");
    }

    public void login() {
        String username = getPara("username");
        String password = getPara("password");
        String sql = "select * from tb_user where username=? and password=?";
        User user = getModel(User.class).findFirst(sql, username, password);
        if (user == null) {
            result.addError("用户名或密码错误!");
            logger.debug("用户名或密码错误! 用户名为{}", username);
        } else {
            setSessionAttr("user", user);
        }
        renderJson(result);
    }
}
